package com.caval.controller;

import com.alibaba.fastjson.JSON;
import com.caval.bean.Comment;
import com.caval.bean.Game;
import com.caval.service.GameService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.util.List;

@Controller
public class GameController {

    @Autowired
    @Qualifier("GameServiceImpl")
    private GameService gameService;

    public void setGameService(GameService gameService) {
        this.gameService = gameService;
    }

    @RequestMapping("/game/getAll")
    @ResponseBody
    public String getAll(){
        return JSON.toJSONString(gameService.getGameList());
    }

    @RequestMapping("/game/getDetail")
    @ResponseBody
    public String getDetail(int game_id){
        return JSON.toJSONString(gameService.getDetail(game_id));
    }

    @RequestMapping("/comment/getComments")
    @ResponseBody
    public String getCommentList(int game_id){
        return JSON.toJSONString(gameService.getCommentList(game_id));
    }

    @RequestMapping("/comment/addComment")
    @ResponseBody
    public String addComment(int game_id, String comment, double score,HttpSession session){
        gameService.addComment((int) session.getAttribute("user_id"),game_id,comment,score);
        return "success";
    }
}
